<template>
  <div style="height:60px;">
    <div style="width: 100%;float: left;font-size: 16px;padding: 9px;cursor: pointer;" @click="getBack"> 
      <i class="el-icon-back"></i>返回<span style="color: #b3b3b3; padding-left: 20px;padding-right: 20px;">/</span>
      <span>{{projectname}}</span>
    </div>
  </div>
  <div class="tabs-group">
    <el-scrollbar style="height: 100%">
      
      <div class="tabs-btns" >
        <button
          v-for="(btn, bIndex) in tabsButtons"
          @click="onClick(btn, bIndex)"
          :class="{ actived: bIndex == index }"
          :key="bIndex"
        >
          <i :class="btn.icon"></i>
          {{ btn.name }}
        </button>
      </div>
      <keep-alive >
        <component ref="com" v-bind:is="currentComponent" ></component>
      </keep-alive>
      <el-row type="flex" justify="center" align="middle" style="height: 100vh">
        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">
          <el-button
            type="warning"
            class="edit_btn"
            @click="btnStaging"
            style="background: #e6a23c 80%;border: #e6a23c;"
            >暂存</el-button
          >&nbsp;&nbsp;&nbsp;&nbsp;
          <el-button type="primary" class="edit_btn" @click="btnSubmit"
            >提交申请</el-button
          >
        </el-col>
      </el-row>
    </el-scrollbar>
  </div>
</template>
<script>
import ssfa from "@/views/upload/ssfa";
import jcbg from "@/views/upload/jcbg";
import zjbg from "@/views/upload/zjbg";
import ljjl from "@/views/upload/ljjl";
import wydcjl from "@/views/upload/wydcjl";
import jjbg from "@/views/upload/jjbg";
import djsjy from "@/views/upload/djsjy";
import wth from "@/views/upload/wth";
import cyd from "@/views/upload/cyd";
import chzlyy from "@/views/upload/chzlyy";
//注意必看，App_Appointment与App_Transaction是自动生成的页面，在页签引用时需要指定表名权限，否则普通帐号打开页面会出现401
//具体指定权限方式见：App_Appointment.js与App_Transaction.js中的tableAction属性
export default {
  components: {
    ssfa,
    jcbg,
    zjbg,
    ljjl,
    wydcjl,
    jjbg,
    djsjy,
    wth,
    cyd,
    chzlyy,
  },

  data() {
    return {
      index: 0,
      currentComponent: "",
      open: false,
      tabsButtons: [],
      projectname: "",
      ssfa: "",
      jcbg: "",
      zjbg: "",
      yjfileInfo: "",
      ljfileInfo: "",
      yj_szzsyxt: "",
      yj_jcsjcg: "",
      yj_scysj: "",
      yj_sdzpsj: "",
      yj_wydcwj: "",
      lj_szzsyxt: "",
      lj_jcsjcg: "",
      lj_scysj: "",
      lj_sdzpsj: "",
      lj_wydcwj: "",
      wydcjl: "",
      jjbg: "",
      jccwwxgsm: "",
      djsjy: "",
      wth: "",
      cyd: "",
      chzlyy: "",
      ssfaValue: "",
      jcbgValue: "",
      zjbgValue: "",
      yj_szzsyxtValue: "",
      yj_jcsjcgValue: "",
      yj_scysjValue: "",
      yj_sdzpsjValue: "",
      yj_wydcwjValue: "",
      lj_szzsyxtValue: "",
      lj_jcsjcgValue: "",
      lj_scysjValue: "",
      lj_sdzpsjValue: "",
      lj_wydcwjValue: "",
      wydcjlValue: "",
      jjbgValue: "",
      jccwwxgsmValue: "",
      djsjyValue: "",
      wthValue: "",
      cydValue: "",
      chzlyyValue: "",
      ssfaName: "",
      jcbgName: "",
      zjbgName: "",
      yj_szzsyxtName: "",
      yj_jcsjcgName: "",
      yj_scysjName: "",
      yj_sdzpsjName: "",
      yj_wydcwjName: "",
      lj_szzsyxtName: "",
      lj_jcsjcgName: "",
      lj_scysjName: "",
      lj_sdzpsjName: "",
      lj_wydcwjName: "",
      wydcjlName: "",
      jjbgName: "",
      jccwwxgsmName: "",
      djsjyName: "",
      wthName: "",
      cydName: "",
      chzlyyName: "",
      yj_isys_dom: 0,
      yj_file_name: "",
      yj_file_path: "",
      lj_file_path: "",
      lj_file_name: "",
      lj_isys_dom: 0,
      stagingState:0,
      parentData:{},
      id:"",
    };
  },

  created() {
    //判断当前作业单位是否存在暂存的记录
   
    this.tabsButtons = [
  
      {
        name: "市县实施方案",
        icon: "el-icon-document",
        component: "ssfa", //上面引用的组件名
      },
      {
        name: "任务区检查报告",
        icon: "el-icon-document",
        component: "jcbg",
        //  table: "/zm_data_record",
      },
      {
        name: "任务区技术总结报告",
        icon: "el-icon-document",
        component: "zjbg",
        // table: "/zm_data_record",
      },
      {
        name: "两级检查记录",
        icon: "el-icon-document",
        component: "ljjl",
        //   table: "/zm_data_record",
      },
      {
        name: "外业调查核查记录表",
        icon: "el-icon-document",
        component: "wydcjl",
        //  table: "/zm_data_record",
      },
      {
        name: "机检记录",
        icon: "el-icon-document",
        component: "jjbg",
        //  table: "/zm_data_record",
      },
      {
        name: "地市级交验",
        icon: "el-icon-document",
        component: "djsjy",
        // table: "/zm_data_record",
      },
      // {
      //   name: "委托函",
      //   icon: "el-icon-document",
      //   component: "wth",
      //   //  table: "/zm_data_record",
      // },
      {
        name: "抽样单",
        icon: "el-icon-document",
        component: "cyd",
        //   table: "/zm_data_record",
      },
      {
        name: "测绘资料交验移交清单",
        icon: "el-icon-document",
        component: "chzlyy",
        //  table: "/zm_data_record",
      },
    ];
    
    //默认显示第一个页面
    if (this.tabsButtons.length) {
      this.currentComponent = this.tabsButtons[0].component;
      console.log(this.tabsButtons[0].component);
      this.getLoad();
    }
  },
  mounted() {
    
  },
  activated() {},
  methods: {
   async getLoad()
    {
      var data_id=this.$route.query.id;
      console.log('***********id***********',data_id)
      this.$store.state.data_id=data_id;
      this.id=data_id;
      this.http
      .post(
          "/api/zm_data_record/AdminGetDetaileByID?id=" +data_id)
          .then((result) => {
              if (result.Data.thisdata != undefined) {
                this.projectname = result.Data.thisdata.projectname;
                this.$store.state.projectname=result.Data.thisdata.projectname
                this.$store.state.projectList=result.Data;
                this.$store.state.filelist = []; //上传文件集合
                console.log(result.Data)
                if(result.Data.thisdata.lj_isys_dom==="1" && result.Data.thisdata.lj_jcsjcg!=null )
                {
                  this.$store.state.ljchecked=true;
                }else
                {
                  this.$store.state.ljchecked=false;
                }

                if(result.Data.thisdata.yj_isys_dom==="1" && result.Data.thisdata.yj_jcsjcg!=null)
                {
                  this.$store.state.yjchecked=true;
                }else
                {
                  this.$store.state.yjchecked=false;
                }
                
              }
        });
    },
    onClick(item, index) {
  
      if (this.index == index) {
        return;
      }
      this.index = index;
      this.currentComponent = item.component;
      if (this.index - 1 == 0) {
        this.btnNext();
      }
      this.$nextTick(() => {
      });
   
    },
    btnNext()
    {

    },
    getBack()
    {
      this.$router.push("/applylist");
    },
    btnStaging() {
      console.log(
        "------------btnStaging------------",
        this.$store.state.filelist
      );
      console.log(
        "------------btnStaging------------",
        this.$store.state.filelist.length
      );

      for (var i = 0; i < this.$store.state.filelist.length; i++) {
        var name = this.$store.state.filelist[i].name;
        var item = this.$store.state.filelist[i].data;
        if (name === "ssfa") {
          if (item.length == 1) {
            this.ssfaValue = item[0].path;
            this.ssfaName = item[0].name;
          }
        } else if (name === "jcbg") {
          if (item.length == 1) {
            this.jcbgValue = item[0].path;
            this.jcbgName = item[0].name;
          }
        } else if (name === "zjbg") {
          if (item.length == 1) {
            this.zjbgValue = item[0].path;
            this.zjbgName = item[0].name;
          }
        }  else if (name === "yj") {
            console.log('888',item)
            var names = "";
            var paths = "";
            if (item.length > 0) {
              for (var n = 0; n < item.length; n++) {
                var filename = item[n].name;
                var filepath = item[n].url;
                names += filename + "|";
                paths += filepath + "|";
              }
              if (names != "" && paths != "") {
                names = names.substring(0, names.length - 1);
                paths = paths.substring(0, paths.length - 1);
              }

              this.yj_file_name = names;
              this.yj_file_path = paths;
              console.log('一级记录',item)
            } else {
            }
          } else if (name === "lj") {
            var names = "";
            var paths = "";
            if (item.length > 0) {
              for (var n = 0; n < item.length; n++) {
                var filename = item[n].name;
                var filepath = item[n].url;
                names += filename + "|";
                paths += filepath + "|";
              }
              if (names != "" && paths != "") {
                names = names.substring(0, names.length - 1);
                paths = paths.substring(0, paths.length - 1);
              }
              this.lj_file_name = names;
              this.lj_file_path = paths;
              console.log('二级记录',this.lj_file_path)
            } 
          } else if (name === "wydcjl") {
          if (item.length == 1) {
            this.wydcjlValue = item[0].path;
            this.wydcjlName = item[0].name;
          }
        } else if (name === "jjbg") {
          if (item.length == 1) {
            this.jjbgValue = item[0].path;
            this.jjbgName = item[0].name;
          }
        } else if (name === "jccwwxgsm") {
          if (item.length == 1) {
            this.jccwwxgsmValue = item[0].path;
            this.jccwwxgsmName = item[0].name;
          }
        } else if (name === "djsjy") {
          if (item.length == 1) {
            this.djsjyValue = item[0].path;
            this.djsjyName = item[0].name;
          }
        } else if (name === "cyd") {
          if (item.length == 1) {
            this.cydValue = item[0].path;
            this.cydName = item[0].name;
          }
        } else if (name === "wth") {
          if (item.length == 1) {
            this.wthValue = item[0].path;
            this.wthName = item[0].name;
          }
        } else if (name === "chzlyy") {
          if (item.length == 1) {
            this.chzlyyValue = item[0].path;
            this.chzlyyName = item[0].name;
          }
        }
      }
      console.log("***参数***", this.projectname);
      var parms = {
        mainData: {
          projectname: this.projectname,
          ssfa: this.ssfaValue,
          jcbg: this.jcbgValue,
          zjbg: this.zjbgValue,
          yj_szzsyxt: this.yj_szzsyxtValue,
          yj_jcsjcg: this.yj_jcsjcgValue,
          yj_scysj: this.yj_scysjValue,
          yj_sdzpsj: this.yj_sdzpsjValue,
          yj_wydcwj: this.yj_wydcwjValue,
          lj_szzsyxt: this.lj_szzsyxtValue,
          lj_jcsjcg: this.lj_jcsjcgValue,
          lj_scysj: this.lj_scysjValue,
          lj_sdzpsj: this.lj_sdzpsjValue,
          lj_wydcwj: this.lj_wydcwjValue,
          wydcjl: this.wydcjlValue,
          jjbg: this.jjbgValue,
          jccwwxgsm: this.jccwwxgsmValue,
          djsjy: this.djsjyValue,
          wth: this.wthValue,
          cyd: this.cydValue,
          chzlyy: this.chzlyyValue,
          ssfa_name: this.ssfaName,
          jcbg_name: this.jcbgName,
          zjbg_name: this.zjbgName,
          yj_szzsyxt_name: this.yj_szzsyxtName,
          yj_jcsjcg_name: this.yj_jcsjcgName,
          yj_scysj_name: this.yj_scysjName,
          yj_sdzpsj_name: this.yj_sdzpsjName,
          yj_wydcwj_name: this.yj_wydcwjName,
          lj_szzsyxt_name: this.lj_szzsyxtName,
          lj_jcsjcg_name: this.lj_jcsjcgName,
          lj_scysj_name: this.lj_scysjName,
          lj_sdzpsj_name: this.lj_sdzpsjName,
          lj_wydcwj_name: this.lj_wydcwjName,
          wydcjl_name: this.wydcjlName,
          jjbg_name: this.jjbgName,
          jccwwxgsm_name: this.jccwwxgsmName,
          djsjy_name: this.djsjyName,
          wth_name: this.wthName,
          cyd_name: this.cydName,
          chzlyy_name: this.chzlyyName,
          yj_isys_dom: this.yj_isys_dom,
          yj_file_name: this.yj_file_name,
          yj_file_path: this.yj_file_path,
          lj_file_path: this.lj_file_path,
          lj_file_name: this.lj_file_name,
          lj_isys_dom: this.lj_isys_dom,
          submit_state: "0",
          id:this.id,
        },
        detailData: null,
        delKeys: null,
      };
      console.log("***参数***", parms);
      this.http.post("/api/zm_data_record/update", parms).then((result) => {
        console.log(result);
        //  this.$message.success(result);
        this.$alert(result.message, "消息提示", {
          confirmButtonText: "确定",
          callback: (action) => {
            console.log("成功");
            // this.$router.push("/applylist");
          },
        });
        //this.$message.success("提交成功，预审意见将在一到两个工作日内完成预审并反馈结果！如有问题，请联系0000-2393993");
      });
    },
    btnSubmit() {
      console.log("------------list------------", this.$store.state.filelist);
      console.log(
        "------------list------------",
        this.$store.state.filelist.length
      );
      var error_msg = [];
      if (this.$store.state.filelist.length>0) {
        for (var i = 0; i < this.$store.state.filelist.length; i++) {
          var name = this.$store.state.filelist[i].name;
          var item = this.$store.state.filelist[i].data;
          
          if (name === "ssfa") {
            if (item.length == 1) {
              this.ssfaValue = item[0].path;
              this.ssfaName = item[0].name;
            } else {
              //error_msg.push("请上传相关实施方案文件！");
            }
          } else if (name === "jcbg") {
            if (item.length == 1) {
              this.jcbgValue = item[0].path;
              this.jcbgName = item[0].name;
            } else {
             // error_msg.push("请上传相关检查报告！");
            }
          } else if (name === "zjbg") {
            if (item.length == 1) {
              this.zjbgValue = item[0].path;
              this.zjbgName = item[0].name;
            } else {
             // error_msg.push("请上传相关技术总结报告！");
            }
          }  else if (name === "yj") {
            console.log('888',item)
            var names = "";
            var paths = "";
            if (item.length > 0) {
              for (var n = 0; n < item.length; n++) {
                var filename = item[n].name;
                var filepath = item[n].url;
                names += filename + "|";
                paths += filepath + "|";
              }
              if (names != "" && paths != "") {
                names = names.substring(0, names.length - 1);
                paths = paths.substring(0, paths.length - 1);
              }

              this.yj_file_name = names;
              this.yj_file_path = paths;
              console.log('一级记录',item)
            } else {
              error_msg.push("请上传【两级记录】中的一级记录！");
            }
          } else if (name === "lj") {
            var names = "";
            var paths = "";
            if (item.length > 0) {
              for (var n = 0; n < item.length; n++) {
                var filename = item[n].name;
                var filepath = item[n].url;
                names += filename + "|";
                paths += filepath + "|";
              }
              if (names != "" && paths != "") {
                names = names.substring(0, names.length - 1);
                paths = paths.substring(0, paths.length - 1);
              }
              this.lj_file_name = names;
              this.lj_file_path = paths;
              console.log('二级记录',this.lj_file_path)
            } else {
              error_msg.push("请上传【两级记录】中的二级记录！");
            }
          } else if (name === "wydcjl") {
            if (item.length == 1) {
              this.wydcjlValue = item[0].path;
              this.wydcjlName = item[0].name;
            } else {
             // error_msg.push("请上传相关外业调查核查记录表！");
            }
          } else if (name === "jjbg") {
            if (item.length == 1) {
              this.jjbgValue = item[0].path;
              this.jjbgName = item[0].name;
            } else {
             // error_msg.push("请上传相关机检记录报告！");
            }
          } else if (name === "jccwwxgsm") {
            if (item.length == 1) {
              this.jccwwxgsmValue = item[0].path;
              this.jccwwxgsmName = item[0].name;
            } else {
            //  error_msg.push("请上传相关机检错误未修改说明！");
            }
          } else if (name === "djsjy") {
            if (item.length == 1) {
              this.djsjyValue = item[0].path;
              this.djsjyName = item[0].name;
            }
          } else if (name === "cyd") {
            if (item.length == 1) {
              this.cydValue = item[0].path;
              this.cydName = item[0].name;
            } else {
             // error_msg.push("请上传相关抽样单！");
            }
          } else if (name === "wth") {
            if (item.length == 1) {
              this.wthValue = item[0].path;
              this.wthName = item[0].name;
            } else {
             // error_msg.push("请上传相关委托函！");
            }
          } else if (name === "chzlyy") {
            if (item.length == 1) {
              this.chzlyyValue = item[0].path;
              this.chzlyyName = item[0].name;
            } else {
             // error_msg.push("请上传相关测绘资料交验移交清单！");
            }
          }
        }
      } 
      
      // {
      //   var fileType = [
      //     { name: "ssfa", title: "实施方案文件" },
      //     { name: "jcbg", title: "检查报告" },
      //     { name: "zjbg", title: "技术总结报告" },
      //     { name: "yj", title: "一级检查记录" },
      //     { name: "lj", title: "两级检查记录" },
      //     { name: "wydcjl", title: "外业调查核查记录表" },
      //     { name: "jjbg", title: "机检记录报告" },
      //     { name: "jccwwxgsm", title: "机检错误未修改说明" },
      //     { name: "cyd", title: "抽样单" },
      //     { name: "wth", title: "委托函" },
      //     { name: "chzlyy", title: "测绘资料交验移交清单" },
      //   ];
      //   var uploadFileType = [];
       
      //     for (var i = 0; i < this.$store.state.filelist.length; i++) {
      //       var name = this.$store.state.filelist[i].name;
      //       uploadFileType.push(name);
      //     }
      //     console.log("***uploadFileType***", uploadFileType);
      //     let result = fileType.filter((item) => {
      //       return uploadFileType.every((item1) => {
      //         return item.name != item1;
      //       });
      //     });
      //     console.log(result);
      //     if (result.length > 0) {
      //       for (var k = 0; k < result.length; k++) {
      //         this.$message.error("请选择上传相关" + result[k].title + "！");
      //       }
      //       return;
      //     }
      // }
     
      // if (error_msg.length > 0) {
      //   for (var k = 0; k < error_msg.length; k++) {
      //     this.$message.error("" + error_msg[k] + "！");
      //   }
      //   return;
      // }
   
      var parms = {
        mainData: {
          projectname: this.projectname,
          id:this.id,
          ssfa: this.ssfaValue,
          jcbg: this.jcbgValue,
          zjbg: this.zjbgValue,
          yj_szzsyxt: this.yj_szzsyxtValue,
          yj_jcsjcg: this.yj_jcsjcgValue,
          yj_scysj: this.yj_scysjValue,
          yj_sdzpsj: this.yj_sdzpsjValue,
          yj_wydcwj: this.yj_wydcwjValue,
          lj_szzsyxt: this.lj_szzsyxtValue,
          lj_jcsjcg: this.lj_jcsjcgValue,
          lj_scysj: this.lj_scysjValue,
          lj_sdzpsj: this.lj_sdzpsjValue,
          lj_wydcwj: this.lj_wydcwjValue,
          wydcjl: this.wydcjlValue,
          jjbg: this.jjbgValue,
          jccwwxgsm: this.jccwwxgsmValue,
          djsjy: this.djsjyValue,
          wth: this.wthValue,
          cyd: this.cydValue,
          chzlyy: this.chzlyyValue,
          ssfa_name: this.ssfaName,
          jcbg_name: this.jcbgName,
          zjbg_name: this.zjbgName,
          yj_szzsyxt_name: this.yj_szzsyxtName,
          yj_jcsjcg_name: this.yj_jcsjcgName,
          yj_scysj_name: this.yj_scysjName,
          yj_sdzpsj_name: this.yj_sdzpsjName,
          yj_wydcwj_name: this.yj_wydcwjName,
          lj_szzsyxt_name: this.lj_szzsyxtName,
          lj_jcsjcg_name: this.lj_jcsjcgName,
          lj_scysj_name: this.lj_scysjName,
          lj_sdzpsj_name: this.lj_sdzpsjName,
          lj_wydcwj_name: this.lj_wydcwjName,
          wydcjl_name: this.wydcjlName,
          jjbg_name: this.jjbgName,
          jccwwxgsm_name: this.jccwwxgsmName,
          djsjy_name: this.djsjyName,
          wth_name: this.wthName,
          cyd_name: this.cydName,
          chzlyy_name: this.chzlyyName,
          yj_isys_dom: this.yj_isys_dom,
          yj_file_name: this.yj_file_name,
          yj_file_path: this.yj_file_path,
          lj_file_path: this.lj_file_path,
          lj_file_name: this.lj_file_name,
          lj_isys_dom: this.lj_isys_dom,
          submit_state: 1,
        },
        detailData: null,
        delKeys: null,
      };
      console.log("***参数***", parms);
      this.http.post("/api/zm_data_record/update", parms).then((result) => {
        console.log(result);
        this.$alert(result.message, "消息提示", {
          confirmButtonText: "确定",
          callback: (action) => {
            if(result.status){
            this.$router.push("/applylist");
            }
          },
        });
      });
    },
  },
};
</script>
<style lang="less" scoped>
.tabs-group {
  position: absolute;
  height: 100%;
  width: 100%;
}
.tabs-btns {
  border-bottom: 1px solid #eee;
  button {
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    margin-right: 20px;
    position: relative;
    padding: 10px 10px 10px 15px;
  }
  button:after {
    content: "/";
    position: absolute;
    right: -16px;
    bottom: 10px;
    color: #b3b3b3;
  }
  button:last-child:after {
    content: "";
    display: none;
  }
  .actived {
    color: black;
    font-weight: bold;
  }
  .message {
    font-size: 12px;
    color: #a2a19e;
    margin-left: 30px;
  }
}
.edit_btn {
  min-height: 40px;
  min-width: 100px;
  background: #409eff 80%;
  border: #409eff;
  font-size: 20px;
}
</style>